35 #ifndef SENSOR_FUSION_TYPES_H 36 #define SENSOR_FUSION_TYPES_H 43 #include "Driver_SPI_SDK2.h" 45 #include "issdk_hal.h" 54 typedef unsigned char byte;
97 #define PI 3.141592654F 98 #define PIOVER2 1.570796327F
99 #define FPIOVER180 0.01745329251994F
100 #define F180OVERPI 57.2957795130823F
101 #define F180OVERPISQ 3282.8063500117F
102 #define ONETHIRD 0.33333333F
103 #define ONESIXTH 0.166666667F
104 #define ONESIXTEENTH 0.0625F
105 #define ONEOVER12 0.083333333F
106 #define ONEOVER48 0.02083333333F
107 #define ONEOVER120 0.0083333333F
108 #define ONEOVER3840 0.0002604166667F
109 #define ONEOVERSQRT2 0.707106781F
110 #define SQRT15OVER4 0.968245837F
111 #define GTOMSEC2 9.80665
142 uint16_t read_loop_counter
153 #define SPI_ADDR 0x00 // Use SPI_ADDR as the address parameter to the installSensor function for SPI-based sensors. 387 float fQwCT6x3[6][3];
421 float fQwCT9x6[9][6];
486 int32_t systick_Spare;
524 #if F_6DOF_GB_BASIC // 6DOF accel and mag eCompass: (accel + mag) 530 #if F_9DOF_GBY_KALMAN 576 uint16_t numElements,
602 uint16_t maxFifoSize,
630 #endif // SENSOR_FUSION_TYPES_H float fChi
tilt from vertical (deg)
float fChiPl
tilt from vertical (deg)
Initializing sensors and algorithms.
SV_3DOF_Y_BASIC structure is the 3DOF basic gyroscope state vector structure.
float flpf
low pass filter coefficient
enum quaternion quaternion_type
the quaternion type to be transmitted
Quaternion derived from full 9-axis sensor fusion.
float fDeltaPl
a posteriori inclination angle from Kalman filter (deg)
Quaternion fq
unfiltered orientation quaternion
void( setStatus_t)(struct SensorFusionGlobals *sfg, fusion_status_t status)
fusion_status_t status
Current status.
void conditionSensorReadings(SensorFusionGlobals *sfg)
conditionSensorReadings() transforms raw software FIFO readings into forms that can be consumed by th...
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
struct AccelSensor AccelSensor
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
int8_t resetflag
flag to request re-initialization on next pass
float fLPH
low pass filtered height (m)
int8_t( readSensor_t)(struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)
float fLPPhi
low pass roll (deg)
float fdeltat
fusion time interval (s)
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
int32_t loopcounter
counter incrementing each iteration of sensor fusion (typically 25Hz)
float fAlphaQwbOver6
(PI / 180 * fdeltat) * Qwb / 6
void addToFifo(FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
Quaternion fq
orientation quaternion
clearFIFOs_t * clearFIFOs
clear sensor FIFOs
int32_t systick_I2C
systick counter to benchmark I2C reads
bool isEnabled
true if the device is sampling
float fLPPsi
low pass yaw (deg)
union FifoSensor FifoSensor
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
Quaternion fq
unfiltered orientation quaternion
uint32_t iFlags
a bit-field of sensors and algorithms used
conditionSensorReadings_t * conditionSensorReadings
preprocessing step for sensor fusion
struct PhysicalSensor PhysicalSensor
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
void initSensorFusionGlobals(SensorFusionGlobals *sfg, struct StatusSubsystem *pStatusSubsystem, struct ControlSubsystem *pControlSubsystem)
utility function to insert default values in the top level structure
int16_t iT
most recent unaveraged temperature (counts)
int32_t systick
systick timer
float fdeltat
fusion time interval (s)
float fAlphaSqQvYQwbOver12
(PI / 180 * fdeltat)^2 * (QvY + Qwb) / 12
Receiving commands over wireless interface (momentary)
float fCountsPerg
counts per g
Functions to convert between various orientation representations.
struct MagSensor MagSensor
The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor...
int32_t systick
systick timer
int16_t iCountsPerDegPerSec
counts per deg/s
Quaternion derived from 3-axis mag only (auto compass algorithm)
float fChi
tilt from vertical (deg)
MagCalibration MagCal
mag cal storage
Implements accelerometer calibration routines.
uint8_t iFIFOCount
number of measurements read from FIFO
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two's complement value for a 16-...
Quaternion fqPl
a posteriori orientation quaternion
Quaternion fLPq
low pass filtered orientation quaternion
struct GyroSensor GyroSensor
The GyroSensor structure stores raw and processed measurements for a 3-axis gyroscope.
The top level fusion structure.
float fLPPhi
low pass roll (deg)
int8_t( initializeSensor_t)(struct PhysicalSensor *sensor, struct SensorFusionGlobals *sfg)
float fdeltat
fusion time interval (s)
float fmPerCount
meters per count
float fLPRho
low pass compass (deg)
int32_t iP
most recent unaveraged pressure (counts)
installSensor_t * installSensor
function for installing a new sensor into t
float fLPRho
low pass compass (deg)
int8_t resetflag
flag to request re-initialization on next pass
int8_t resetflag
flag to request re-initialization on next pass
float fAlphaSqOver4
(PI / 180 * fdeltat)^2 / 4
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
float fLPPsi
low pass yaw (deg)
#define MAG_FIFO_SIZE
FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.
StatusSubsystem() provides an object-like interface for communicating status to the user...
void clearFIFOs(SensorFusionGlobals *sfg)
Function to clear FIFO at the end of each fusion computation.
Quaternion derived from 3-axis gyro only (rotation)
These are the state definitions for the status subsystem.
int16_t iCountsPeruT
counts per uT
void testStatus(SensorFusionGlobals *sfg)
Quaternion derived from 3-axis accel + 3 axis mag (eCompass)
This is the 3DOF basic accelerometer state vector structure.
int16_t iCountsPerg
counts per g
readSensor_t * read
pointer to function to read sensor using the supplied drivers
Quaternion derived from 3-axis accel + 3-axis gyro (gaming)
#define ACCEL_FIFO_SIZE
FXOS8700 (accel), MMA8652, FXLS8952 all have 32 element FIFO.
struct SV_3DOF_G_BASIC SV_3DOF_G_BASIC
This is the 3DOF basic accelerometer state vector structure.
The AccelSensor structure stores raw and processed measurements for a 3-axis accelerometer.
float fLPThe
low pass pitch (deg)
void ApplyGyroHAL(GyroSensor *Gyro)
Apply the gyroscope Hardware Abstraction Layer.
readSensors_t * readSensors
read all physical sensors
float fMaxGyroOffsetChange
maximum permissible gyro offset change per iteration (deg/s)
struct ControlSubsystem * pControlSubsystem
Magnetic Calibration Structure.
int8_t( readSensors_t)(struct SensorFusionGlobals *sfg, uint16_t read_loop_counter)
float fgdeltat
g (m/s2) * fdeltat
initializeFusionEngine_t * initializeFusionEngine
set sensor fusion structures to initial values
MagSensor Mag
magnetometer storage
float fcosDeltaPl
cos(fDeltaPl)
Quaternion fLPq
low pass filtered orientation quaternion
The SV_1DOF_P_BASIC structure contains state information for a pressure sensor/altimeter.
This is the 3DOF basic magnetometer state vector structure/.
float fDelta
unfiltered inclination angle (deg)
quaternion structure definition
uint16_t schedule
Parameter to control sensor sampling rate.
#define GYRO_FIFO_SIZE
FXAX21000, FXAS21002 have 32 element FIFO.
Recoverable FAULT = something went wrong, but we can keep going.
int8_t resetflag
flag to request re-initialization on next pass
int32_t iH
most recent unaveraged height (counts)
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
float fLPChi
low pass tilt from vertical (deg)
float fLPPsi
low pass yaw (deg)
updateStatus_t * updateStatus
status=next status
The PressureSensor structure stores raw and processed measurements for an altimeter.
float fLPThe
low pass pitch (deg)
initializeFusionEngine_t initializeFusionEngine
uint8_t iWhoAmI
sensor whoami
struct PhysicalSensor * next
pointer to next sensor in this linked list
struct SV_6DOF_GY_KALMAN SV_6DOF_GY_KALMAN
SV_6DOF_GY_KALMAN is the 6DOF Kalman filter accelerometer and gyroscope state vector structure...
quaternion
the quaternion type to be transmitted
float fLPT
low pass filtered temperature (C)
float fuTPerCount
uT per count
Quaternion fq
unfiltered orientation quaternion
float fRhoPl
compass (deg)
float fAlphaQwbOver6
(PI / 180 * fdeltat) * Qwb / 6
initializeSensor_t * initialize
pointer to function to initialize sensor using the supplied drivers
bool isEnabled
true if the device is sampling
float fMaxGyroOffsetChange
maximum permissible gyro offset change per iteration (deg/s)
SV_6DOF_GB_BASIC is the 6DOF basic accelerometer and magnetometer state vector structure.
float flpf
low pass filter coefficient
float fAlphaSqOver4
(PI / 180 * fdeltat)^2 / 4
void ApplyAccelHAL(AccelSensor *Accel)
Apply the accelerometer Hardware Abstraction Layer.
float fsinDeltaPl
sin(fDeltaPl)
float fChiPl
tilt from vertical (deg)
struct SV_1DOF_P_BASIC SV_1DOF_P_BASIC
The SV_1DOF_P_BASIC structure contains state information for a pressure sensor/altimeter.
int32_t systick
systick timer
int8_t( installSensor_t)(struct SensorFusionGlobals *sfg, struct PhysicalSensor *sensor, uint16_t addr, uint16_t schedule, void *bus_driver, initializeSensor_t *initialize, readSensor_t *read)
void( clearFIFOs_t)(struct SensorFusionGlobals *sfg)
void( ssUpdateStatus_t)(struct StatusSubsystem *pStatus)
Receiving commands over wired interface (momentary)
Running in reduced power mode.
int32_t systick
systick timer;
struct PressureSensor PressureSensor
The PressureSensor structure stores raw and processed measurements for an altimeter.
float fLPChi
low pass tilt from vertical (deg)
Matrix manipulation functions.
Lower level magnetic calibration interface.
float fdeltat
sensor fusion interval (s)
uint8_t iFIFOCount
number of measurements read from FIFO
float fdeltat
sensor fusion interval (s)
he ControlSubsystem encapsulates command and data streaming functions.
float fLPThe
low pass pitch (deg)
Quaternion fq
unfiltered orientation quaternion
accelerometer measurement buffer
void( ssSetStatus_t)(struct StatusSubsystem *pStatus, fusion_status_t status)
float fH
most recent unaveraged height (m)
float fCPerCount
degrees Celsius per count
void( conditionSensorReadings_t)(struct SensorFusionGlobals *sfg)
struct SV_3DOF_B_BASIC SV_3DOF_B_BASIC
This is the 3DOF basic magnetometer state vector structure/.
spiSlaveSpecificParams_t slaveParams
SPI specific parameters. Not used for I2C.
int8_t resetflag
flag to request re-initialization on next pass
int8_t resetflag
flag to request re-initialization on next pass
int8_t iFirstAccelMagLock
denotes that 9DOF orientation has locked to 6DOF eCompass
void( updateStatus_t)(struct SensorFusionGlobals *sfg)
MagBuffer MagBuffer
mag cal constellation points
void ApplyMagHAL(MagSensor *Mag)
Apply the magnetometer Hardware Abstraction Layer.
uint8_t iWhoAmI
sensor whoami
readSensors_t readSensors
struct SensorFusionGlobals SensorFusionGlobals
The top level fusion structure.
runFusion_t * runFusion
run the fusion routines
struct StatusSubsystem * pStatusSubsystem
float fCountsPeruT
counts per uT
Non-recoverable FAULT = something went very wrong.
float fdeltat
fusion filter sampling interval (s)
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
float fLPChi
low pass tilt from vertical (deg)
void( applyPerturbation_t)(struct SensorFusionGlobals *sfg)
void( initializeFusionEngine_t)(struct SensorFusionGlobals *sfg)
uint8_t iFIFOCount
number of measurements read from FIFO
float fAlphaOver2
PI / 180 * fdeltat / 2.
struct SV_6DOF_GB_BASIC SV_6DOF_GB_BASIC
SV_6DOF_GB_BASIC is the 6DOF basic accelerometer and magnetometer state vector structure.
struct SV_3DOF_Y_BASIC SV_3DOF_Y_BASIC
SV_3DOF_Y_BASIC structure is the 3DOF basic gyroscope state vector structure.
uint16_t iFIFOExceeded
Number of samples received in excess of software FIFO size.
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
Quaternion fqPl
a posteriori orientation quaternion
float fLPDelta
low pass filtered inclination angle (deg)
uint8_t iWhoAmI
sensor whoami
Quaternion fLPq
low pass filtered orientation quaternion
installSensor_t installSensor
float fdeltat
fusion time interval (s)
Quaternion derived from 3-axis accel (tilt)
float fT
most recent unaveraged temperature (C)
float fgPerCount
g per count
setStatus_t * queueStatus
queue status change for next regular interval
float fLPRho
low pass compass (deg)
float fAlphaOver2
PI / 180 * fdeltat / 2.
The MagSensor structure stores raw and processed measurements for a 3-axis magnetic sensor...
float fRhoPl
compass (deg)
fusion_status_t
Application-specific serial communications system.
int8_t resetflag
flag to request re-initialization on next pass
float flpf
low pass filter coefficient
setStatus_t * setStatus
change status indicator immediately
struct AccelBuffer AccelBuffer
accelerometer measurement buffer
The Magnetometer Measurement Buffer holds a 3-dimensional "constellation" of data points...
SensorFusionGlobals sfg
This is the primary sensor fusion data structure.
struct SV_9DOF_GBY_KALMAN SV_9DOF_GBY_KALMAN
SV_9DOF_GBY_KALMAN is the 9DOF Kalman filter accelerometer, magnetometer and gyroscope state vector s...
uint8_t iWhoAmI
sensor whoami
applyPerturbation_t * applyPerturbation
apply step function for testing purposes
int32_t systick
systick timer
float fQv
measurement noise covariance matrix leading diagonal
float fDegPerSecPerCount
deg/s per count
bool isEnabled
true if the device is sampling
int32_t systick
systick timer;
float fLPPhi
low pass roll (deg)
Excluding SV_1DOF_P_BASIC, Any of the SV_ fusion structures above could be cast to type SV_COMMON for...
The GyroSensor structure stores raw and processed measurements for a 3-axis gyroscope.
uint16_t addr
I2C address if applicable.
precision accelerometer calibration structure
void( runFusion_t)(struct SensorFusionGlobals *sfg)
float flpf
low pass filter coefficient
struct SV_COMMON SV_COMMON
Excluding SV_1DOF_P_BASIC, Any of the SV_ fusion structures above could be cast to type SV_COMMON for...
volatile uint8_t iPerturbation
test perturbation to be applied
SV_6DOF_GY_KALMAN is the 6DOF Kalman filter accelerometer and gyroscope state vector structure...
applyPerturbation_t ApplyPerturbation
ApplyPerturbation is a reverse unit-step test function.
PhysicalSensor * pSensors
a linked list of physical sensors
int32_t systick
systick timer
SV_9DOF_GBY_KALMAN is the 9DOF Kalman filter accelerometer, magnetometer and gyroscope state vector s...
void zeroArray(struct StatusSubsystem *pStatus, void *data, uint16_t size, uint16_t numElements, uint8_t check)
bool isEnabled
true if the device is sampling
float fAlphaSqQvYQwbOver12
(PI / 180 * fdeltat)^2 * (QvY + Qwb) / 12
int32_t systick
systick timer;